# -*- coding:utf-8 -*-
from flask import request, jsonify, abort
from flask_cors import CORS
from com.zzh.dao_v2.counselorDao import CounselorDao

from . import app

CORS(app, supports_credentials=True)


@app.route('/insertCounselor', methods=['POST'])
def insert_counselor():
    """
    添加信息
    :return:
    """
    if not request.json:
        abort(400)
    info = {
        'counName': request.json.get('counName', ''),
        'counPhone': request.json.get('counPhone', ''),
        'counAddress': request.json.get('counAddress', '')
    }

    info = CounselorDao().insertCounselor(info)
    if info==0:
        return jsonify({"message": {"code": 0, "status": "counselor already exist!"}})
    elif info==1:
        return jsonify({"message": {"code": 1, "status": "success"}})
    else:
        return jsonify({"message": {"code": -1, "status": "error"}})